<?php

class m_pasien extends CI_Model {

    public function getAllPasien() {
        $strSql = "SELECT * FROM tb_pasien";
        $strQuery = $this->db->query($strSql);
        if ($strQuery->num_rows() > 0) {
            foreach ($strQuery->result_array() as $val) {
                $arrHasil[] = $val;
            }
            $strQuery->free_result();
            return $arrHasil;
        } else {
            return array();
        }
    }

    public function getAllPasienWithLimit($pArrParam) {
        $strSql = "SELECT * FROM tb_pasien LIMIT ?,?";
        $strQuery = $this->db->query($strSql, $pArrParam);
        if ($strQuery->num_rows() > 0) {
            foreach ($strQuery->result_array() as $val) {
                $arrHasil[] = $val;
            }
            $strQuery->free_result();
            return $arrHasil;
        } else {
            return array();
        }
    }

    public function getPasien($pIntPasienId) {
        $strSql = "SELECT * FROM tb_pasien WHERE id_pasien=?";
        $strQuery = $this->db->query($strSql, $pIntPasienId);
        if ($strQuery->num_rows() > 0) {
            foreach ($strQuery->result_array() as $val) {
                $arrHasil[] = $val;
            }
            $strQuery->free_result();
            return $arrHasil;
        } else {
            return array();
        }
    }

    public function saveAdd($pArrParams) {
        $strSql = "INSERT INTO tb_pasien(nama,jenis_kelamin,kota_lahir,tanggal_lahir,telp,alamat,gol_darah,pekerjaan,tanggal_daftar) VALUES (?,?,?,?,?,?,?,?,?)";
        return $this->db->query($strSql, $pArrParams);
    }

    public function saveEdit($pArrParams) {
        $strSql = "UPDATE tb_pasien SET nama=?, jenis_kelamin=?, kota_lahir=?, tanggal_lahir=?, telp=?, alamat=?, gol_darah=?, pekerjaan=?, tanggal_daftar=? WHERE id_pasien=?";
        return $this->db->query($strSql, $pArrParams);
    }

    function delete($pStrDokterId) {
        $strSql = "DELETE FROM tb_pasien WHERE id_pasien=?";
        return $this->db->query($strSql, $pStrDokterId);
    }

    function count() {
        return $this->db->count_all_results("tb_pasien");
    }

}

?>
